import { io } from 'socket.io-client'
import { ElMessage } from 'element-plus'
// import { setItem, getItem } from '../storage/session'
class Socket {
  socket = null;
  ioAddress;
  connect () {
    this.socket = io(`${window.config.socketEchart}`)
    this.socket.on('connect', () => {
      console.log('连接服务端成功')
    })
    this.socket.on('connect_error', () => {
      ElMessage({
        message: '连接失败,服务端异常',
        type: 'error'
      })
    })
    this.socket.on('disconnect', (reason) => {
      console.log(reason)
    })
  }

  send (type, value) {
    this.socket.emit(type, value)
  }

  receive (type, callback) {
    this.socket.on(type, callback)
  }

  disConnect () {
    this.socket.disconnect()
  }
}
export default Socket
